package cn.blunce.greendaoinandroidstudio.activities;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import java.util.List;

import cn.blunce.greendaoinandroidstudio.R;
import cn.blunce.greendaoinandroidstudio.base.DBHelper;
import cn.blunce.greendaoinandroidstudio.models.Job;
import cn.blunce.greendaoinandroidstudio.models.Person;

public class MainActivity extends Activity {
    private final String TAG = "DBTest";

    private DBHelper mDBHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mDBHelper = DBHelper.getInstance(this);

//        test_add();
//        toPrint();
    }

    private void test_add() {
        for (int i = 0; i < 5; i++) {
            Person person = new Person(System.currentTimeMillis());
            person.setName(String.valueOf(person.getId()).substring(5));
            person.setAge((int) (person.getId() % 100));
            Job job = new Job(String.valueOf(System.currentTimeMillis()));
            job.setContent(job.getCategory().substring(6));
            mDBHelper.add(person);
            mDBHelper.add(job);
        }
        toPrint();
    }

    private void toPrint() {
        List<Person> persons = mDBHelper.getAllPersons();
        Log.i(TAG, "***********************************************");
        Log.i(TAG, "Persons in DB:\t" + persons.size());
        Log.i(TAG, "id\t\t\t\tname\t\tage");
        for (Person person : persons)
            Log.i(TAG, person.toString());
        Log.i(TAG, "***********************************************");
        List<Job> jobs = mDBHelper.getAllJobs();
        Log.i(TAG, "Jobs in DB:" + jobs.size());
        Log.i(TAG, "id\t\t\t\tcontent");
        for (Job job : jobs)
            Log.i(TAG, job.toString());
        Log.i(TAG, "***********************************************");
    }
}
